﻿using System;

namespace MultiConvert
{
    class SEAssemblyConverter : SEDocumentConverter 
    {
        private SolidEdgeAssembly.AssemblyDocument Document;
        public SEAssemblyConverter(Object SolidEdgeDoc, SEApplicationWrapper Base)
        {
            this.Application = Base;
            this.Document = (SolidEdgeAssembly.AssemblyDocument)SolidEdgeDoc;
            this.HighlightSets = this.Document.HighlightSets;
        }

        internal override String convert(String ConvertMethod, String toFileName)
        {
            this.ConversionResult = Properties.Resources.MsgConvFailed;
            switch (ConvertMethod)
            {
                case "asm2par_simpl":

                    try
                    {
                        if (this.Document.IsAssemblySimplified == false)
                        {
                            // Variablen für Ermittlung und Behandlung Anzahl Occurrence
                            Int32 AnzahlOccurrences;
                            Int32 NumOccurrenceExclude;
                            Int32 NumOccurrenceInclude;
                            Double dExcludeRangeRatio;
                                                        
                            // Setzen Variablen für Behandlung Occurrences
                            AnzahlOccurrences = this.Document.Occurrences.Count;
                            SolidEdgeAssembly.Occurrence[] OccurrenceInclude = new SolidEdgeAssembly.Occurrence[AnzahlOccurrences];
                            SolidEdgeAssembly.Occurrence[] OccurrenceExclude = new SolidEdgeAssembly.Occurrence[0];
                            NumOccurrenceInclude = AnzahlOccurrences;
                            NumOccurrenceExclude = 0;  
                            dExcludeRangeRatio = 0;
                    
                            // Befüllen des Arryes für IncludeOccurrence und Alle sichtbar
                            for (int i = 0; i < AnzahlOccurrences; i++)
                            {
                                OccurrenceInclude[i] = Document.Occurrences.Item(i+1);
                                Document.Occurrences.Item(i+1).Visible = true;
                            }
                            
                            // Aufruf SolidEdgeObject.Methoden zum Erzeugen Vereinfachung ASM                      
                            this.Document.DeleteSimplifiedAssembly();
                            this.Document.ActivateAll();
                            this.Document.CreateOrEditSimplifiedAssembly(NumOccurrenceExclude, OccurrenceExclude, dExcludeRangeRatio, NumOccurrenceInclude, OccurrenceInclude);
                            this.ConversionResult = Properties.Resources.MsgConvByCreatedEnvelope;
                        }
                        else
                        {
                            this.ConversionResult = Properties.Resources.MsgConvByExistingEnvelope;
                        }

                        this.Document.SaveSimplifiedAssemblyAs(toFileName);  

                    }
                    catch(Exception ex)
                    {
                        throw new ConvertException(ex.ToString(), ex);
                    }                    
                    break;
                    
                case "asm2x_t":
                case "asm2igs":
                case "asm2jt":
                case "asm2stp":                
            		this.ConversionResult = this.SaveAs( (SolidEdgeFramework.SolidEdgeDocument)this.Document, toFileName, ConvertMethod );                    
                    break;

                case "asm2jpg":
                    this.ConversionResult = this.SaveAsImage((SolidEdgeFramework.SolidEdgeDocument)this.Document, toFileName, ConvertMethod);
                    break;
                    
                default:
                    this.ConversionResult = Properties.Resources.MsgNoConvImplemented;
                    break;
            }
            return this.ConversionResult;
        }
    }
}
